#ifndef __PROG_GROUP_H
#define __PROG_GROUP_H

#include "stdint.h"
#include "mytype.h"

#ifdef __cplusplus
extern "C"
{
#endif

#define PG_ERR_NONE 0
#define PG_ERR_TAB_FULL -1
#define PG_ERR_PHY_REUSE -2
#define PG_ERR_SEG_REUSE -3
#define PG_ERR_PHY_NOUSE -4
#define PG_ERR_SEG_NOUSE -5
#define PG_ERR_GROUP_NOUSE -6
#define PG_ERR_SUB_FULL -7
#define PG_ERR_PHY_LIMIT -8

	union pg_element_str
	{
		struct
		{
			ii16 phy;  
			ii8 sub;   
			ii8 group; 
		} prog;

		ii32 info;
	};

	struct pg_man_str
	{
		union pg_element_str *tab; 
		uu16 *phy_used_st;		   
		ii16 tab_size;			   
		ii8 group_max;			   
		ii8 sub_max;			   
								   
		ii8 head_fix;			   
		ii8 cycle;				   

		int8_t err;	  
		uu16 act_amount; 
		
		ii16 site; 
		union pg_element_str result;
	};

	int8_t pg_init(struct pg_man_str *, union pg_element_str *tab, uu16 *phy_st, ii16 tab_size);

	int8_t pg_mode(struct pg_man_str *, char head_fix, char cycle);

	int8_t pg_size(struct pg_man_str *, ii8 group_max, ii8 sub_max);

	int8_t pg_add(struct pg_man_str *, ii8 group, ii8 sub, ii16 phy);

	int8_t pg_del_site(struct pg_man_str *pg, ii16 site);

	int8_t pg_del_phy(struct pg_man_str *, ii16 phy);

	int8_t pg_del_seg(struct pg_man_str *, ii8 group, ii8 sub);

	int8_t pg_phy_site(struct pg_man_str *, ii16 phy);

	int8_t pg_seg_site(struct pg_man_str *, ii8 group, ii8 sub);

	int8_t pg_next_site(struct pg_man_str *, ii16 site);

	int8_t pg_next_phy(struct pg_man_str *, ii16 phy);

	int8_t pg_next_seg(struct pg_man_str *, ii8 group, ii8 sub);

	int8_t pg_fore_site(struct pg_man_str *, ii16 site);

	int8_t pg_fore_phy(struct pg_man_str *, ii16 phy);

	int8_t pg_fore_seg(struct pg_man_str *, ii8 group, ii8 sub);

	int8_t pg_group_site(struct pg_man_str *, ii8 group);

	int8_t pg_gp_sapce_sub_get(struct pg_man_str *, ii8 group);

	int8_t pg_gp_sapce_phy_get(struct pg_man_str *);

	ii16 pg_seg_amount(struct pg_man_str *);

	ii16 pg_gp_seg_amount(struct pg_man_str *pg, ii8 group);

#ifdef __cplusplus
}
#endif

#endif 
